<?php
    header('Access-Control-Allow-Origin:*');
    include('./config.php');
    include('./pathConfig.php');
    $imageFiles = $_FILES['imgfile'];
    if($imageFiles['name']!=""){
    $extName = explode(".",$imageFiles['name']);
    $fileExtName = $extName[count($extName)-1];
    $imgName = $extName[count($extName)-2];
    $fileName = "imgs/".$imageFiles['name'];
    move_uploaded_file($imageFiles['tmp_name'],$fileName);
    // echo $serpath."imgs/".$imageFiles['name'];
    try{
        $pdo = new PDO($dsn,$user,$pass);
        $sql = "update goods set imgpath='".$serpath."imgs/".$imageFiles['name']."' where goods_name='".$imgName."'";
        $res = $pdo->prepare($sql);
        $res->execute();
        if($res){
            echo json_encode($res);
        }else{
            echo "error";
        }
    }catch(PDOException $e){
            echo "error";
        }
    }   
?>